package com.le.tester.javaThink.fifth.chapter18_Str;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * createTime：2021/8/13 11:45
 * description：匹配的正则表达式
 */
public class TestRegularExpression {
    public static void main(String[] args) {
        if (args.length < 2) {
            System.out.println("Usage:java TestRegularExpression " +
                    "characterSequence regularExpression+");
            System.exit(0);
        }
        System.out.println("Input:\"" + args[0] + "\"");
        for (String sItem : args) {
            System.out.println(
                    "Regular expression: \"" + sItem + "\"");
            Pattern p = Pattern.compile(sItem);
            Matcher m = p.matcher(args[0]);
            while (m.find()) {
                //find()返回boolean
                System.out.println(
                        "Match \"" + m.group() + "\" at positions " +
                                m.start() + "-" + (m.end() - 1));
            }
        }
    }
}
